Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
24 lines (17 loc) · 783 Bytes

7.3.10 - Http/Response::create.md

File metadata and controls

24 lines (17 loc) · 783 Bytes

Http\Response::create

构造新的Http\Response对象。使用此方法前请务必调用detach方法将旧的$response对象分离,否则可能会造成对同一个请求发送两次响应内容。

function Http\Response::create(int $fd) : Http\Response;
  • 参数为需要绑定的连接$fd,调用Http\Response对象的endwrite方法时会向此连接发送数据
  • 调用成功返回一个新的Http\Response对象,调用失败返回false

需要2.2.0或更高版本

$http = new Swoole\Http\Server("0.0.0.0", 9501);

$http->on('request', function ($req, Swoole\Http\Response $resp) use ($http) {
    $resp->detach();
    $resp2 = Swoole\Http\Response::create($req->fd);
    $resp2->end("hello world");
});

$http->start();